<template>
  <Page name="订单详情">
    <ui-loading v-if="initLoading" class="page-init-loading">
      <div slot="content"></div>
    </ui-loading>
    <div class="order-details" v-else>
      <h4 class="title">
        <span>{{data.shop_info.name}} </span>
      </h4>
      <ul class="goods">
        <li v-for="item in data.order_goods" >
          <div class="thumb">
            <img :src="item.thumb" alt="">
          </div>
          <div class="info">
            <h4>
              <span class="name">{{item.goods_name}}</span>
              <span>{{item.price}} {{item.currency_code}}</span>
            </h4>
            <p>{{item.num}}</p>
          </div>
        </li>
      </ul>
      <div class="total">
        订单金额：<span>{{data.order_info.amount}}{{data.order_info.currency_code}}</span>  
      </div>
      <div class="discount" v-if="data.order_info.cash_amount !='' ">
        <span class="label">现金支付</span>
        <span class="num">-{{data.order_info.cash_amount}}{{data.order_info.currency_code}}</span>
        <span class="label">折扣减免</span>
        <span class="num">-{{data.order_info.discount_amount}}{{data.order_info.currency_code}}</span>
      </div>
      <div class="payable_amount">
        剩余应付金额: <span>{{data.order_info.payable_amount}}{{data.order_info.currency_code}}</span>  
      </div>
      <ul class="list">
        <li>
          <span>订单号</span>
          <span>{{data.order_info.order_id}}</span>
        </li>
        <li>
          <span>状态</span>
          <span>{{data.order_info.status_str}}</span>
        </li>
        <li>
          <span>付款方式</span>
          <span>{{data.order_info.pay_type_str}}</span>
        </li>
        <li>
          <span>创建时间</span>
          <span>{{data.order_info.addtime}}</span>
        </li>
        <li>
          <span>是否存疑订单</span>
           <span>{{data.order_info.is_question==1?'是':'否'}}</span>
        </li>
        <li>
          <span v-if="data.order_info.question_time!=''">存疑时间</span>
          <span>{{data.order_info.question_time}}</span>
        </li>
        <li>
          <span>存疑次数</span>
          <span>{{data.order_info.question_counts}}</span>
        </li>
        <li v-if="data.order_info.question_cs.nickname!=''">
          <span>受理人</span>
           <span>{{data.order_info.question_cs.nickname}}</span>
        </li>
      </ul>
      <ui-popup :status="popup.status" @close="popupClose">
        <div class="popup-common exit-pop" :class="questionType != 'comfirm' ?'h280':''">
            <div class="exit-content">
                <p> {{ popInfo.title }} </p>
                <textarea v-model="popInfo.content" v-if="questionType=='comfirm'"></textarea>
            </div>
            <div class="footer">
                <a href="javascript:;" @click="popupClose">取消</a>
                <a href="javascript:;" @click="confirm(true)" :class="questionType== 'comfirm' && popInfo.content==''?'gray':''">确定</a>
            </div>
        </div>
      </ui-popup>
      <div class="h88" v-if="data.order_info.is_can_question==1 || data.order_info.is_can_question==0 || data.order_info.order_status==-1 || data.order_info.status==0"></div>
      <footer v-if="data.order_info.is_can_question==1 || data.order_info.is_can_question==0 || data.order_info.order_status==-1 || data.order_info.status==0" >
          <button v-if="data.order_info.is_can_question==1" @click="getPop(data.order_info.order_id,'cancel')">取消存疑</button>
          <button v-if="data.order_info.is_can_question==0" @click="getPop(data.order_info.order_id,'comfirm')">存疑</button>
          <button v-if="data.order_info.order_status==-1 " class="pay-btn" @click="goToPay(data.order_info.order_id)">立即支付</button>
          <button v-if="data.order_info.status==0 " @click="getPop(data.order_info.order_id,'sure')">确认订单</button>
      </footer>
    </div>
  </Page>
</template>

<script>
import Page from '~/components/page';
import UILoading from  "~/components/loading";
import popup from "~/components/common/popup";
export default {
  components: {
    Page,
    [UILoading.name]: UILoading,
    [popup.name]: popup,
  },
  data() {
    return {
      initLoading:true,
      data:{
        shop_info:{},
        order_goods:[],
        order_info:{}
      },
      pupStatus:false,
      popInfo: {
          title: "",
          content: ""
      },
      popup: {
          status: false
      },
      order_id:"",
      questionType:""
  }  
  },
  mounted(){
    (async () => {
        await this.getDate();
    })();
  },
  methods: {
    async getDate(status) {
      let { data: rs } = await this.$axios.post('?ct=api&ac=order_detail',{
        order_id:this.$utils.getUrlKey("order_id")
      })
      if (rs.code == 0) {
        this.data.order_info = rs.data.order_info;
        this.data.order_goods = rs.data.order_goods;
        this.data.shop_info = rs.data.shop_info;
        
        this.initLoading = false;
      } else {
        this.$toast(rs.msg);
        window.history.go(-1);
        this.initLoading = false;
      }
    },
    getPop (id,type) {
      if(type=="comfirm"){
        this.popInfo.title = "确认发起存疑？";
        this.questionType = "comfirm";
      }else if(type=="sure"){
        this.popInfo.title = "确认订单？";
        this.questionType = "sure";
      }else{
         this.popInfo.title = "确认取消存疑？";
         this.questionType = "cancel";
      }
      this.popup.status = true;
      this.order_id = id;
    },
    popupClose () {
      this.popup.status = false;
    },
    confirm (flag) {
      if(this.questionType=='comfirm'){
        if(this.popInfo.content==''){
          return false;
        }
      }
      this.popup.status = false;
      let order_id = this.order_id;
      this.question_order(order_id);
    },
    async question_order(id){
      let params = {};
      let url = "";
      if(this.questionType=="comfirm"){
        url = '?ct=api&ac=question_order';
        params = {
          order_id:id,
          question:this.popInfo.content
        }
      }else if(this.questionType=="cancel"){
        url = '?ct=api&ac=cancal_question_order';
        params = {
          order_id:id,
        }
      }else{
        url = '?ct=api&ac=commit_order';
        params = {
          order_id:id,
        }
      }
      let { data:rs } = await this.$axios.post(url,params)
      if(rs.code == 0){
        this.$toast(rs.msg);
        setTimeout(function(){
          window.location.reload();
        },1000)
      }else{
        this.$toast(rs.msg);
      }
    },
    goToPay(order_id){
      if(this.$utils.getUrlKey('type')=='elsepay'){
        this.$router.push({name:'pay-confirm',query:{id:order_id,type:'order',elsepay:1}})
      }else{
        this.$router.push({name:'pay-confirm',query:{id:order_id,type:'order'}})
      }
      
    }
  }
}
</script>

<style lang="less" scoped>
  .order-details{
    h4.title{
      line-height: 80px;
      font-size:28px;
      font-weight: normal;
      border-bottom:1px solid #ededed;
      background: #fff;
      margin-top:20px;
      padding:0 30px;
    }
    ul.goods {
      background: #fff;
      padding:20px 30px;
      li{
        display: flex;
        display:-webkit-flex;
        flex-direction: row;
        margin-bottom:20px;
        border-bottom:1px solid #ededed;
        padding-bottom:20px;
        &:last-child{
          border-bottom:0;
          padding-bottom:0;
        }
        .thumb{
          width:108px;
          height:108px;
          margin-right:20px;
          img{
            width:108px;
            height:108px;
          }
        }
        .info{
          flex: 1;
          h4{
            display: flex;
            display:-webkit-flex;
            font-size:28px;
            color:#292929;
            font-weight: normal;
            margin-bottom:20px;
            .name{
              width:360px;
              display: block;
            }
            span:last-child{
              flex: 1;
              text-align: right;
              color:#999;
            }
          }
          p{
            text-align: right;
            color:#999;
          }
        }
        
      }
    }
    .total{
      line-height: 80px;
      text-align: right;
      border-top:1px solid #ededed;
      font-size:30px;
      color:#666;
      background: #fff;
      padding:0 30px;
      span:last-child{
        font-weight: 600;
      }
    }
    .payable_amount{
      line-height: 120px;
      text-align: right;
      border-top:1px solid #ededed;
      font-size:28px;
      //color:#f05521;
      background: #fff;
      padding:0 30px;
      border-bottom:4px dashed #ededed; 
      border-bottom-style: dotted;
      span:last-child{
        font-weight: 600;
        color:#f05521;
        font-size:42px;
      }
    }
    .discount{
      line-height: 80px;
      text-align: right;
      border-top:1px solid #ededed;
      font-size:28px;
      color:#292929;
      background: #fff;
      padding:0 30px;
      .label{
        border:1px solid #f05521;
        line-height: 24px;
        color:#f05521;
        padding:3px 6px;
        border-radius: 3px;
        display: inline-block;
        font-size:18px;
      }
    }
    .list{
      line-height:80px;
      color:#666;
      font-size:30px;
      padding:0 30px;
      background: #fff;
      padding-top:30px;
      li{
        span:last-child{
          float: right;
          color:#292929;
        }
      }
    }
    footer{
      position: fixed;
      bottom:0;
      left:0;
      z-index: 1;
      line-height: 100px;
      background: #fff;
      height: 100px;
      width:100%;
      text-align: right;
      border-top:2px solid #ededed; 
      button{
        padding:0 30px;
        background: none;
        border:none;
        border-left:1px solid #ededed;
        height:100px;
        color:#2086f9;
        font-size:30px;
      }
      .pay-btn{
        background: #2086f9;
        color:#fff;
      }
      
    }
    .h88{
      height:140px;
    }
  }
   .popup-common {
      position: absolute;
      left: 11%;
      background: #fff;
      z-index: 999;
      border-radius: 10px;
  }

  .exit-pop {
      top: 40%;
      width: 600px;
      height: 430px;
      &.h280{
        height:280px;
      }
      .exit-content {
          margin-top: 60px;
          text-align: center;
          p {
              margin-top: 40px;
              font-size: 36px;
              color: #282828;
          }
          textarea{
            width:460px;
            height:150px;
            border:2px solid #ededed;
            border-radius: 4px;
            margin-top:20px;
            padding:10px;
            box-shadow: none;
          }
      }
      .footer {
        position: absolute;
        bottom: 0;
        width: 100%;
        display: flex;
        a {
          display: inline-block;
          width: 50%;
          padding: 30px 0;
          text-align: center;
          font-size: 36px;
          border-top: 1px solid #e2e2e2;
          color: #2086f9;
          &:first-child {
              
            border-right: 1px solid #e2e2e2;
          }
         
        }
        .gray{
          color:#999;
        }
      }
  }
</style>
